<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Linkage_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
    }
	/**
	 * 查询
	 * @param $data
	 */
	function get_linkage_list($type_id=0){
		if($type_id>0){
			$key = 'rsh_linkage_'.$type_id;
			$list = $this->mycache->get_array($key);
			if($list == false){
				$this->db->select('id,fvalue');
				$this->db->where('type_id', $type_id);
				$query = $this->db->get('rsh_linkage');
				$result = $query->result_array();
				$list = array();
				foreach($result as $val){
					$list[$val['id']] = $val['fvalue'];
				}
				$this->mycache->set_array($key,$list,0);
			}
		}else{
			$key = 'rsh_linkage';
			$list = $this->mycache->get_array($key);
			if($list == false){
				$this->db->select('id,type_id,pid,name,fvalue');
				$query = $this->db->get('rsh_linkage');
				$result = $query->result_array();
				$list = array();
				foreach($result as $val){
					$list[$val['id']] = $val;
				}
				$this->mycache->set_array($key,$list,0);
			}
		}
		return $list;
		
		/*
		$this->db->select('id,type_id,pid,name,fvalue');
		if($type_id > 0){
			$this->db->where('type_id', $type_id);
		}
		$query = $this->db->get('rsh_linkage');
		$result = $query->result_array();
		$list = array();
		foreach($result as $val){
			$list[$val['id']] = $val;
		}
		return $list;
		*/
	}
}